<template>
	<view class="bg-white flex flex-direction" style="height: 100vh;">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">
				<text>文章</text>
			</block>
		</cu-custom>
		<!-- 专栏组件 -->
		<column :columnType="1" class="flex-sub flex  flex-direction" :tablist="tablist" ref="column" @change="handleChange">
			<!-- 轮播展示 -->
			<swiper class="margin flex-sub" @change="onSwiperchange" :current="current">
				<swiper-item v-for="(item,num) in tablist" :key="num">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="loadMoreData">
						<view v-for="(art,index) in articlelist" :key="index" class="margin-top" style="animation: slide-bottom .8s 1;">
							<!-- 展示列表 -->
							<artcell :art="art"></artcell>
						</view>
						<load-more :status="item.loadMoreStatus"></load-more>
					</scroll-view>
				</swiper-item>
			</swiper>
		</column>
	</view>
</template>

<script>
	import cuCustom from '../../plugin/colorui/components/cu-custom.vue'
	import column from '../../components/column/column.vue'
	import artcell from '../../components/column/artcell.vue'
	import articleApi from "../../api/articleApi.js"
	import loadMore from '../../components/mine/loadMore.vue';
	export default {
		components: {
			column,
			artcell,
			loadMore
		},
		data() {
			return {
				page: 1,
				current: 0, //swiper当前滑块
				tablist: [],
				articlelist: [],
			}
		},
		onLoad() {
			this.$http.get('/edu/onesubject/getAllOneSubject').then(res =>{
				this.tablist=res.data.result
				this.tablist.forEach(item =>{
					item.loadMoreStatus=0
					item.id="a"+item.id
				})
				// console.log(this.tablist)
			})
			articleApi.getAllArticle().then(res => {
				this.articlelist = res.data
				this.articlelist.forEach((item, index) => {
					// console.log(item.id)

					item["imglist"] = item.cover.split(",")
					item.content=item.content.replace(/<img[^>]*>/gi,function(match,capture){
						match=""
						return match
					})
					delete item.cover
				})
			})
		},
		methods: {
			loadMoreData() {
				// this.tablist[this.current].loadMoreStatus = 1;
				// // 更改加载页数
				// this.page++;

				// if (this.articlelist.length < 15) {
				// 	this.articlelist = this.articlelist.concat(this.articlelist);
				// 	this.tablist[this.current].loadMoreStatus = 0;
				// } else {
				// 	this.tablist[this.current].loadMoreStatus = 2;
				// 	this.$forceUpdate()
				// }
			},
			onSwiperchange(e) {
				this.$refs.column.switchtab(e.detail.current)
				this.current = e.detail.current
				this.tablist[this.current].loadMoreStatus = 0;
			},
			handleChange(index) {
				this.current = index
				this.tablist[this.current].loadMoreStatus = 0;
			},
		}
	}
</script>

<style>
</style>
